package ru.ifmo.trafficspy.provider;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import ru.ifmo.trafficspy.common.Interval;
import ru.ifmo.trafficspy.common.Item;
import ru.ifmo.trafficspy.common.Packet;

public class SimpleProvider extends Provider {

	private final Random random;
	
	private final int maxLen;
	private final int packetSize;
	private final int intervalLength;
	
	public SimpleProvider(int maxLen, int packetSize, int intervalLength) {
		super("Simple provider: maxLen = " + maxLen + " packetSize = " + packetSize + " intervalLength = " + intervalLength);
		this.maxLen = maxLen;
		this.random = new Random();
		this.packetSize = packetSize;
		this.intervalLength = intervalLength;
	}
	
	@Override
	public List<Item> getTraffic() {
		int n = random.nextInt(maxLen) + 1;
		ArrayList<Item> res = new ArrayList<Item>();
		res.add(new Packet(packetSize));
		for (int i = 0; i < n - 1; i++) {
			res.add(new Interval(intervalLength));
			res.add(new Packet(packetSize));		
		}
		return res;
	}

}
